home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Item Class / Item sources / CTypingTask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  1.1 KB  |  70 lines  |  [TEXT/KAHL]

  1. /*
  2.  * File:        CTypingTask.cp
  3.  * Created:        8/10/93
  4.  * Desc:        A task to accumulate characters as the they are typed.
  5.  *
  6.  * Superclass:    CTask.
  7.  * Uses:        CPane.
  8.  *
  9.  * Note:        
  10.  *
  11.  * Original Author:    W. Wesley Monroe
  12.  * Copyright © 1993 Animas Software Production. All rights reserved.
  13.  */
  14.  
  15.  
  16. #include "CTypingTask.h"
  17. #include "CItemTable.h"
  18.  
  19. void CTypingTask::ITypingTask(CItemTable *itsTable, short taskIndex)
  20. {
  21.     fTable = itsTable;
  22.     
  23.     ITask(taskIndex);
  24.  
  25.     fStillTyping = TRUE;
  26.     fAccumulatedChars[0] = 0;
  27.     fStartTicks = TickCount();
  28. }
  29.  
  30. void CTypingTask::Dispose(void)
  31. {
  32.     if(fTable->fTypingTask == this)
  33.         fTable->fTypingTask = NULL;
  34.  
  35.     inherited::Dispose();
  36. }
  37.  
  38. Boolean CTypingTask::CanStillType(void)
  39. {
  40.     return fStillTyping;
  41. }
  42.  
  43. void CTypingTask::CancelTyping(void)
  44. {
  45.  
  46.     fAccumulatedChars[0] = 0;
  47. }
  48.  
  49. #define    kTimeout    200
  50.  
  51. void CTypingTask::DoTyping(char aChar)
  52. {
  53.     short    numChars = fAccumulatedChars[0];
  54.     char    *buff = fAccumulatedChars;
  55.  
  56.     if(fStartTicks + kTimeout > TickCount()) {
  57.  
  58.         buff[0] = ++numChars;    
  59.         buff[numChars] = aChar;
  60.  
  61.     } else {
  62.  
  63.         fStillTyping = FALSE;
  64.         buff[0] = 1;    
  65.         buff[1] = aChar;
  66.  
  67.     }
  68.  
  69.     fTable->SelectMatchingText(buff);
  70. }